/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import domain.controller.rms.MObjectController;
import domain.controller.rms.MObjectLoader;
import domain.controller.rms.RecordStorePool;
import domain.model.rms.UsuarioConfig;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;

/**
 *
 * @author ademar.victorino
 */
public class AppHelper {

    protected MIDlet midlet = null;
    public Hashtable screens = new Hashtable(0);

    public void exitMidlet() {
        RecordStorePool.getInstance().closeAllRecordStore();
        midlet.notifyDestroyed();
    }

    public Display getDisplay() {
        return Display.getDisplay(midlet);
    }

    public MIDlet getMidletDefault() {
        return midlet;
    }

    public UsuarioConfig getUc() {
        UsuarioConfig uc;
        Enumeration en = MObjectController.listMObject(MObjectLoader.TYPE_USUARIOCONFIG);
        if (en.hasMoreElements()) {
            uc = (UsuarioConfig) en.nextElement();
        } else {
            uc = new UsuarioConfig();
            uc.save();
        }
        return uc;
    }

    public void setMidlet(MIDlet midlet) {
        this.midlet = midlet;
    }

    public void setUc(UsuarioConfig uc) {
        uc.save();
    }

}
